package com.primb.bench.common.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.widget.RelativeLayout;

import com.zhy.autolayout.AutoRelativeLayout;
import com.zhy.autolayout.utils.AutoLayoutHelper;


/**
 *
 * @author Chen
 * @date 2017/6/20
 * 功能描述：
 */

public class LineLayout extends AutoRelativeLayout {

    private int heightSize;
    private boolean isDrawHeader = true;
    private boolean isDrawFooter = true;
    private final AutoLayoutHelper mHelper = new AutoLayoutHelper(this);

    public LineLayout(Context context) {
        super(context);
    }

    public LineLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public LineLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

    }

    @Override
    protected void dispatchDraw(Canvas canvas) {
        super.dispatchDraw(canvas);
        Paint paint = new Paint();
        paint.setAntiAlias(true);
        paint.setColor(Color.parseColor("#77d6f2"));
        paint.setStrokeWidth(10f);
        paint.setStyle(Paint.Style.FILL);

        if (isDrawHeader) {
            canvas.drawLine(0, 0, 0, 120, paint);
        }

        if (isDrawFooter) {
            canvas.drawLine(0, 120, 0, heightSize, paint);
        }
    }

    public void setDrawHeader(boolean drawHeader) {
        isDrawHeader = drawHeader;
    }

    public void setDrawFooter(boolean drawFooter) {
        isDrawFooter = drawFooter;
    }

    @Override
    public AutoRelativeLayout.LayoutParams generateLayoutParams(AttributeSet attrs) {
        return new AutoRelativeLayout.LayoutParams(getContext(), attrs);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        heightSize = getMeasuredHeight();
        if (!isInEditMode()) {
            mHelper.adjustChildren();
        }
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }

}
